<template>
  <div class="dimension">
    <div class="container">
      <div class="top">
        <span>维度转换</span>
        <!--地区-->
        <img :src="imgUrl" alt @click="$store.state.dimensionState = false" />
      </div>
      <div class="main">
        <div class="row">
          <div></div>
          <div class="row_main">
            <div :class="{active:colVal==='指标'}" @click="changeTabel('指标','col')">指标</div>
            <div :class="{active:colVal==='地区'}" @click="changeTabel('地区','col')">地区</div>
            <div :class="{active:colVal==='时间'}" @click="changeTabel('时间','col')">时间</div>
          </div>
        </div>
        <div class="col">
          <div class="row_main">
            <div :class="{active:rowVal==='指标'}" @click="changeTabel('指标','row')">指标</div>
            <div :class="{active:rowVal==='地区'}" @click="changeTabel('地区','row')">地区</div>
            <div :class="{active:rowVal==='时间'}" @click="changeTabel('时间','row')">时间</div>
          </div>
          <div class="tabel">
            <div>
              <div>{{rowVal}}</div>
              <div>{{colVal}}</div>
              <div>{{colVal}}</div>
              <div>{{colVal}}</div>
            </div>
            <div>
              <div>{{rowVal}}</div>
              <div></div>
              <div></div>
              <div></div>
            </div>
            <div>
              <div>{{rowVal}}</div>
              <div></div>
              <div></div>
              <div></div>
            </div>
            <div>
              <div>{{rowVal}}</div>
              <div></div>
              <div></div>
              <div></div>
            </div>
          </div>
        </div>
      </div>
      <div class="bottom">
        <div @click="trueChange()">确定</div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'dimension',
  data () {
    return {
      imgUrl: require('../../../static/nav/deleteImg.png'),
      rowVal: '指标',
      colVal: '时间',
      arrValue: {
        '指标': 'zb',
        '时间': 'sj',
        '地区': 'dq'
      },
      arrValueZd: {
        'zb': '指标',
        'sj': '时间',
        'dq': '地区'
      }
    }
  },
  methods: {
    changeTabel (stateSD, strd) {
      console.log(stateSD, strd, 'stateSD, strd')
      if (strd === 'row') {
        this.rowVal = stateSD
      } else if (strd === 'col') {
        this.colVal = stateSD
      }
    },
    // 维度转换默认
    change3D () {
      console.log(this.$store.state.SelecttDimension, '3d56')
      this.rowVal = this.arrValueZd[this.$store.state.SelecttDimension.col]
      this.colVal = this.arrValueZd[this.$store.state.SelecttDimension.row]
    },
    // 确定维度转换
    trueChange () {
      if (this.rowVal === this.colVal) {
        // alert('维度转换格式错误！行列相同')
        this.$alert('维度转换格式错误！行列相同', '温馨提示', {
          confirmButtonText: '确定'
        })
      } else {
        this.trueChangeArea(false)
      }
    },
    trueChangeArea (dataState) {
      this.$store.newSelectChangeData = null
      console.log(dataState, 'dataState')
      console.log(this.$store.state.noChangeData.areaName, 'this.$store.state.noChangeData.areaName')
      /* eslint-disable*/
      console.log(this.arrValue[this.colVal], 'this.$store.state.noChangeDatathis.$store.state.noChangeDatathis.$store.state.noChangeData')
      console.log(this.arrValue[this.rowVal], 'this.$store.state.noChangeDatathis.$store.state.noChangeDatathis.$store.state.noChangeData')
      console.log(this.$store.state.noChangeData)
      let paramsd = {}
      if ((this.arrValue[this.colVal] === 'sj' && this.arrValue[this.rowVal] === 'zb') || (this.arrValue[this.colVal] === 'zb' && this.arrValue[this.rowVal] === 'sj')) {
        this.$store.state.noSelecttDimension = 'dq'
        paramsd = {
          type: this.$route.query.type === 'area' ? 2 : 1, // 1非地区   2地区
          data: this.$store.state.selectDataLeft.id,
          area: dataState ? dataState : this.$store.state.noChangeData.areaName[0], // 选中的地区
          quota: '', // 选中的指标
          cate: this.selectState, // 1筛选指标  2筛选地区
          f: this.$store.state.selectDataLeft.f, // year=>年度分类，monthly=>月度分类，quarter=>季度分类
          // filters: this.$store.state.selectfilter, // year=>年度分类，monthly=>月度分类，quarter=>季度分类
          date: '', // 时间
          row: this.arrValue[this.colVal],
          col: this.arrValue[this.rowVal]
        }
        this.$store.state.newSelectChangeData = paramsd.area
      } else if ((this.arrValue[this.colVal] === 'sj' && this.arrValue[this.rowVal] === 'dq') || (this.arrValue[this.colVal] === 'dq' && this.arrValue[this.rowVal] === 'sj')) {
        this.$store.state.noSelecttDimension = 'zb'
        paramsd = {
          type: this.$route.query.type === 'area' ? 2 : 1, // 1非地区   2地区
          data: this.$store.state.selectDataLeft.id,
          area: '', // 选中的地区
          quota: dataState ? dataState : this.$store.state.noChangeData.termsName[0], // 选中的指标
          cate: this.selectState, // 1筛选指标  2筛选地区
          f: this.$store.state.selectDataLeft.f, // year=>年度分类，monthly=>月度分类，quarter=>季度分类
          // filters: this.$store.state.selectfilter, // year=>年度分类，monthly=>月度分类，quarter=>季度分类
          date: '', // 时间
          row: this.arrValue[this.colVal],
          col: this.arrValue[this.rowVal]
        }
        this.$store.state.newSelectChangeData = paramsd.quota
      } else if ((this.arrValue[this.colVal] === 'zb' && this.arrValue[this.rowVal] === 'dq') || (this.arrValue[this.colVal] === 'dq' && this.arrValue[this.rowVal] === 'zb')) {
        this.$store.state.noSelecttDimension = 'sj'
        paramsd = {
          type: this.$route.query.type === 'area' ? 2 : 1, // 1非地区   2地区
          data: this.$store.state.selectDataLeft.id,
          area: '', // 选中的地区
          quota: '', // 选中的指标
          cate: this.selectState, // 1筛选指标  2筛选地区
          f: this.$store.state.selectDataLeft.f, // year=>年度分类，monthly=>月度分类，quarter=>季度分类
          // filters: this.$store.state.selectfilter, // year=>年度分类，monthly=>月度分类，quarter=>季度分类
          date: dataState ? dataState : this.$store.state.noChangeData.timeArr[0], // 时间
          row: this.arrValue[this.colVal],
          col: this.arrValue[this.rowVal]
        }
        this.$store.state.newSelectChangeData = paramsd.date
      }
      this.$store.state.SelecttDimension.row = this.arrValue[this.colVal]
      this.$store.state.SelecttDimension.col = this.arrValue[this.rowVal]
      console.log(this.$store.state.SelecttDimension, 'this.$store.state.SelecttDimension0236')
      this.$axios({
        method: 'POST',
        url: 'data/data/wd-trans',
        data: paramsd
      }).then(res => {
        console.log(this.$store.state.transBefore, '维度转换全局数据')
        console.log(res, '获取数据展示数据')
        // 请求接口完成   请求成功
        if (res.data.code === 200) {
          // if (res.data.data.areaName.length !== 0) {
          let transBefore = {}
          if ((this.arrValue[this.colVal] === 'sj' && this.arrValue[this.rowVal] === 'zb') || (this.arrValue[this.colVal] === 'zb' && this.arrValue[this.rowVal] === 'sj')) {
            transBefore.timeArr = res.data.data.timeArr.map((item, index) => { return item.toString() })
            transBefore.termsName = res.data.data.termsName
            transBefore.areaName = this.$store.state.transBefore.areaName
            transBefore.termsExplain = res.data.data.termsExplain
            transBefore.dataSource = res.data.data.dataSource
            this.$store.newSelectChangeData = this.$store.state.dataArealabelTime.areaArr
          } else if ((this.arrValue[this.colVal] === 'sj' && this.arrValue[this.rowVal] === 'dq') || (this.arrValue[this.colVal] === 'dq' && this.arrValue[this.rowVal] === 'sj')) {
            transBefore.timeArr = res.data.data.timeArr.map((item, index) => { return item.toString() })
            transBefore.termsName = this.$store.state.transBefore.termsName
            transBefore.areaName = res.data.data.areaName
            transBefore.termsExplain = this.$store.state.transBefore.termsExplain
            transBefore.dataSource = this.$store.state.transBefore.dataSource
            this.$store.newSelectChangeData = this.$store.state.dataArealabelTime.quotaArr
          } else if ((this.arrValue[this.colVal] === 'zb' && this.arrValue[this.rowVal] === 'dq') || (this.arrValue[this.colVal] === 'dq' && this.arrValue[this.rowVal] === 'zb')) {
            transBefore.timeArr = this.$store.state.transBefore.timeArr.map((item, index) => { return item.toString() })
            transBefore.termsName = res.data.data.termsName
            transBefore.areaName = res.data.data.areaName
            transBefore.termsExplain = res.data.data.termsExplain
            transBefore.dataSource = res.data.data.dataSource
            this.$store.newSelectChangeData = this.$store.state.dataArealabelTime.timeArr
          }
          transBefore.tableExplain = res.data.data.tableExplain
          transBefore.transBeforeTermsData = res.data.data.transBeforeTermsData
          // 转置后请求数据需要将数据转置
          // if (!this.$store.state.yesNoClickZZ) {
          //   let transBeforeAreaData = JSON.parse(JSON.stringify(res.data.data.transBeforeAreaData[0]))
          //   transBefore.transBeforeAreaData = transBeforeAreaData[0].map((col, index) => {
          //     return transBeforeAreaData.map((row, key) => {
          //       return row[index]
          //     })
          //   })
          // } else {
          //   transBefore.transBeforeAreaData = res.data.data.transBeforeAreaData[0]
          // }
          transBefore.transBeforeAreaData = res.data.data.transBeforeAreaData[0]
          console.log(transBefore, '000')
          this.$store.state.transdtr = true
          // 全局总数据
          this.$store.state.AreaAllCountData = JSON.parse(JSON.stringify(res.data.data))
          this.$store.state.transBefore = transBefore
          // 告诉父组件维度转换发生改变
          this.$emit('areaDimensionState', true)
          // }
        } else {
          this.$store.state.transBefore = null
          // 告诉父组件维度转换发生改变
          this.$emit('areaDimensionState', true)
        }
        // 关闭窗口
        this.$store.state.dimensionState = false
        if (this.$route.query.type === 'area') {
          this.$store.state.noAreadimensionState = false
          this.$store.state.areaDimensionState = true
        } else {
          this.$store.state.noAreadimensionState = true
          this.$store.state.areaDimensionState = false
        }
        this.$store.state.allNochangeInitData = JSON.parse(JSON.stringify(this.$store.state.transBefore))
        let transpositionDatas = JSON.parse(JSON.stringify(this.$store.state.allNochangeInitData.transBeforeAreaData))
        if (this.$store.state.befaultAfter === 'zz') {
          this.$store.state.allNochangeInitData.transBeforeAreaData = transpositionDatas[0].map(function (col, index) {
            return transpositionDatas.map((row, key) => {
              return row[index]
            })
          })
          // this.$store.state.befaultAfter = 'wdzh'
        }
        this.$store.state.yesNoClickChange = true
      }).catch((fail) => {
        console.log(fail, 2369)
      })
    }
  },
  mounted() {
    this.change3D()
    console.log(1003)
  }
}
</script>
<style lang="scss" scoped>
.dimension {
  width: 100%;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.4);
  position: fixed;
  top: 0;
  bottom: 0;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  z-index: 10;
  & > .container {
    width: 64.375rem;
    height: 33rem;
    background-color: #ffffff;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    & > .top {
      margin-top: 1rem;
      width: 59.375rem;
      height: 3.875rem;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
      border-bottom: 0.125rem solid #bdbdbd;
      font-size: 1.375rem;
      font-weight: normal;
      font-stretch: normal;
      letter-spacing: 0rem;
      color: #333333;
      & > img {
        width: 1.3125rem;
        height: 1.3125rem;
      }
      & > img:hover {
        cursor: pointer;
      }
    }
    & > .main {
      margin-top: 2.6rem;
      width: 59.375rem;
      & > .row {
        width: 59.375rem;
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: center;
        & > div:nth-child(1) {
          width: 5.25rem;
          height: 3.125rem;
        }
        & > .row_main {
          display: flex;
          flex-direction: row;
          justify-content: flex-start;
          align-items: center;
          & > div {
            width: 5.25rem;
            height: 3.125rem;
            background-color: #a8daf1;
            display: flex;
            flex-direction: row;
            justify-content: center;
            align-items: center;
            color: #fff;
          }
          & > div:nth-child(1) {
            border-radius: 0.1875rem 0 0 0.1875rem;
          }
          & > div:nth-child(3) {
            border-radius: 0 0.1875rem 0.1875rem 0;
          }
          & > .active {
            background-color: #52b6e3;
          }
        }
        & > div:hover {
          cursor: pointer;
        }
      }
      & > .col {
        width: 59.375rem;
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: flex-start;
        & > .row_main {
          display: flex;
          flex-direction: column;
          justify-content: flex-start;
          align-items: center;
          & > div {
            width: 5.25rem;
            height: 3.125rem;
            background-color: #a8daf1;
            display: flex;
            flex-direction: row;
            justify-content: center;
            align-items: center;
            color: #fff;
          }
          & > div:nth-child(1) {
            border-radius: 0.1875rem 0 0 0.1875rem;
          }
          & > div:nth-child(3) {
            border-radius: 0 0.1875rem 0.1875rem 0;
          }
          & > .active {
            background-color: #52b6e3;
          }
          & > div:hover {
            cursor: pointer;
          }
        }
        & > .tabel {
          display: flex;
          flex-direction: column;
          justify-content: flex-start;
          align-items: flex-start;
          & > div {
            height: 2.5rem;
            display: flex;
            flex-direction: row;
            justify-content: flex-start;
            align-items: center;
            & > div {
              height: 2.5rem;
              width: 13.265rem;
              display: flex;
              flex-direction: row;
              justify-content: center;
              align-items: center;
              border: 1px solid black;
            }
          }
        }
      }
    }
    & > .bottom {
      width: 59.375rem;
      display: flex;
      flex-direction: row;
      justify-content: center;
      align-items: flex-start;
      & > div:nth-child(1) {
        width: 15.625rem;
        height: 3.1875rem;
        background-color: #52b6e3;
        border-radius: 0.3125rem;
        font-size: 1.25rem;
        font-weight: normal;
        font-stretch: normal;
        letter-spacing: 0rem;
        color: #ffffff;
        display: flex;
        flex-direction: row;
        justify-content: center;
        align-items: center;
      }
      & > div:nth-child(2) {
        width: 15.625rem;
        height: 3.1875rem;
        border: solid 0.125rem #dbdbdb;
        border-radius: 0.3125rem;
        font-size: 1.25rem;
        font-weight: normal;
        font-stretch: normal;
        letter-spacing: 0rem;
        color: #666666;
        display: flex;
        flex-direction: row;
        justify-content: center;
        align-items: center;
      }
      & > div {
        margin: 3rem 1.2rem;
      }
      & > div:hover {
        cursor: pointer;
      }
    }
  }
}
</style>
